﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kristall.MyGame.Projectiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Kristall.Engine;
using Kristall.Managers;

namespace Kristall.MyGame.Weapons
{
    public class PlasmaLauncher : Weapon 
    {
        float fireCooldownTimer = 0;
        bool fired = false;

        public override float CoolDownTime
        {
            get
            {
                return Kristall.Options.player_firecooldown;
            }            
        }

        AnimatableSprite gun;

        public override void LoadContent(Level level)
        {
            gun = new AnimatableSprite("Weapons/PlasmaLauncher.xnb");
            gun.FrameHeight = 11;
            Animations.Clear();
            Animations.Add(gun);
            this.CurrentAnimationKey = "Weapons/PlasmaLauncher.xnb";

            base.LoadContent(level);

            gun.FrameCount = 1;

            this.Height = 11;
            this.Width = 20;

            CheckPlayerCollision = false;
            CheckWorldCollision = false;
            
        }

        public override void Fire()
        {
            if (fireCooldownTimer == 0)
            {
                TestProjectile tp = new TestProjectile(Level.Player);
                tp.Direction = (Level.Player.VerticalLookDirection == Vector2.Zero ? Level.Player.LookDirection : Level.Player.VerticalLookDirection);
                tp.LoadContent(Level);
                tp.Center = Level.Player.Center;
                Level.PlayerProjectiles.Add(tp);
                
            }
        }

        public override void HandleInput(InputState inputState)
        {
            if (inputState.IsKeyPressed(Keys.X))
            {
                Fire();
                fired = true;
            }
        }

        public override void UpdateWeapon(float dt)
        {
            if (fireCooldownTimer >= CoolDownTime)
            {
                fireCooldownTimer = 0;
                fired = false;
            }
            else if (fired == true)
                fireCooldownTimer += dt;
        }        
    }
}
